home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / specilbm < prev    next >
Text File  |  1986-04-20  |  21KB  |  491 lines

  1.  
  2. "ILBM" IFF Interleaved Bitmap
  3.  
  4. Date:     January 17, 1986
  5. From:     Jerry Morrison, Electronic Arts
  6. Status:   Released and in use
  7.  
  8. 1. Introduction
  9.  
  10. "EA IFF 85" is Electronic Arts' standard for interchange format files. 
  11. "ILBM" is a format for a 2 dimensional raster graphics image, specifically 
  12. an InterLeaved bitplane BitMap image with color map. An ILBM is an 
  13. IFF "data section" or "FORM type", which can be an IFF file or a part 
  14. of one. (See the IFF reference.)
  15.  
  16. An ILBM is an archival representation designed for three uses. First, 
  17. a standalone image that specifies exactly how to display itself (resolution, 
  18. size, color map, etc.). Second, an image intended to be merged into 
  19. a bigger picture which has its own depth, color map, and so on. And 
  20. third, an empty image with a color map selection or "palette" for 
  21. a paint program. ILBM is also intended as a building block for composite 
  22. IFF FORMs like "animation sequence" and "structured graphics". Some 
  23. uses of ILBM will be to preserve as much information as possible across 
  24. disparate environments. Other uses will be to store data for a single 
  25. program or highly cooperative programs while maintaining subtle details. 
  26. So we're trying to accomplish a lot with this one format.
  27.  
  28. This memo is the IFF supplement for FORM ILBM. Section 2 defines the 
  29. purpose and format of property chunks bitmap header "BMHD", color 
  30. map "CMAP", hotspot "GRAB", destination merge data "DEST", sprite 
  31. information "SPRT", and Commodore Amiga viewport mode "CAMG". Section 
  32. 3 defines the standard data chunk "BODY". These are the "standard" 
  33. chunks. Section 4 defines the nonstandard color range data chunk "CRNG". 
  34. Additional specialized chunks like texture pattern can be added later. 
  35. The ILBM syntax is summarized in Appendix A as a regular expression 
  36. and in Appendix B as a box diagram. Appendix C explains the optional 
  37. run encoding scheme. Appendix D names the committee responsible for 
  38. this FORM ILBM standard.
  39.  
  40. Details of the raster layout are given in part 3, "Standard Data Chunk". 
  41. Some elements are based on the Commodore Amiga hardware but generalized 
  42. for use on other computers. An alternative to ILBM would be appropriate 
  43. for computers with true color data in each pixel.
  44.  
  45. Reference:
  46.  
  47. "EA IFF 85" Standard for Interchange Format Files describes the underlying 
  48. conventions for all IFF files.
  49.  
  50. Amiga[tm] is a trademark of Commodore-Amiga, Inc.
  51. Electronic Arts[tm] is a trademark of Electronic Arts.
  52. Macintosh[tm] is a trademark licensed to Apple Computer, Inc.
  53. MacPaint[tm] is a trademark of Apple Computer, Inc.
  54.  
  55.  
  56. 2. Standard Properties
  57.  
  58. The required property "BMHD" and any optional properties must appear 
  59. before any "BODY" chunk. (Since an ILBM has only one BODY chunk, any 
  60. following properties are superfluous.) Any of these properties may 
  61. be shared over a LIST of FORMs IBLM by putting them in a PROP ILBM. 
  62. (See the "EA IFF 85" memo.)
  63.  
  64. BMHD
  65.  
  66. The required property "BMHD" holds a BitMapHeader as defined in these 
  67. C declarations and following documentation. It describes the dimensions 
  68. and encoding of the image, including data necessary to understand 
  69. the BODY chunk to follow.
  70.  
  71. typedef UBYTE Masking;   /* Choice of masking technique. */
  72.  
  73. #define mskNone     0
  74. #define mskHasMask  1
  75. #define mskHasTransparentColor     2
  76. #define mskLasso    3
  77.  
  78. typedef UBYTE Compression;    
  79.      /* Choice of compression algorithm applied to the rows of all 
  80.       * source and mask planes. "cmpByteRun1" is the byte run encoding 
  81.       * described in Appendix C. Do not compress across rows! */
  82. #define cmpNone     0
  83. #define cmpByteRun1 1
  84.  
  85. typedef struct {
  86.      UWORD w, h;    /* raster width & height in pixels */
  87.      WORD  x, y;    /* pixel position for this image   */
  88.      UBYTE nPlanes; /* # source bitplanes    */
  89.      Masking masking;
  90.      Compression compression;
  91.      UBYTE pad1;    /* unused; for consistency, put 0 here  */
  92.      UWORD transparentColor;  /* transparent "color number" (sort of) */
  93.      UBYTE xAspect, yAspect;  /* pixel aspect, a ratio width : height */
  94.      WORD  pageWidth, pageHeight;  /* source "page" size in pixels    */
  95.      } BitMapHeader;
  96.  
  97. Fields are filed in the order shown. The UBYTE fields are byte-packed.
  98.  
  99. The fields w and h indicate the size of the image rectangle in pixels. 
  100. Each row of the image is stored in an integral number of 16 bit words. 
  101. The number of words per row is Ceiling(w/16). The fields x and y indicate 
  102. the desired position of this image within the destination picture. 
  103. Some reader programs may ignore x and y. A safe default for writing 
  104. an ILBM is (x, y) = (0, 0).
  105.  
  106. The number of source bitplanes in the BODY chunk (see below) is stored 
  107. in nPlanes. An ILBM with a CMAP but no BODY and nPlanes = 0 is the 
  108. recommended way to store a color map.
  109.  
  110. Note: Color numbers are color map index values formed by pixels in 
  111. the destination bitmap, which may be deeper than nPlanes if a DEST 
  112. chunk calls for merging the image into a deeper image.
  113.  
  114. The field masking indicates what kind of masking is to be used for 
  115. this image. The value mskNone designates an opaque rectangular image. 
  116. The value mskHasMask means that a mask plane is interleaved with the 
  117. bitplanes in the BODY chunk (see below). The value mskHasTransparentColor 
  118. indicates that pixels in the source planes matching transparentColor 
  119. are to be considered "transparent". (Actually, transparentColor isn't 
  120. a "color number" since it's matched with numbers formed by the source 
  121. bitmap rather than the possibly deeper destination bitmap. Note that 
  122. having a transparent color implies ignoring one of the color registers. 
  123. See CMAP, below.) The value mskLasso indicates the reader may construct 
  124. a mask by lassoing the image as in MacPaint*. To do this, put a 1 
  125. pixel border of transparentColor around the image rectangle. Then 
  126. do a seed fill from this border. Filled pixels are to be transparent.
  127.  
  128. Issue: Include in an appendix an algorithm for converting a transparent 
  129. color to a mask plane, and maybe a lasso algorithm.
  130.  
  131. A code indicating the kind of data compression used is stored in compression. 
  132. Beware that using data compression makes your data unreadable by programs 
  133. that don't implement the matching decompression algorithm. So we'll 
  134. employ as few compression encodings as possible. The run encoding 
  135. byteRun1 is documented in Appendix C, below.
  136.  
  137. The field pad1 is a pad byte and must be set to 0 for consistency. 
  138. This field could get used in the future.
  139.  
  140. The transparentColor specifies which bit pattern means "transparent".  
  141. This only applies if masking is mskHasTransparentColor or mskLasso 
  142. (see above). Otherwise, transparentColor should be 0.
  143.  
  144. The pixel aspect ratio is stored as a ratio in the two fields xAspect 
  145. and yAspect. This may be used by programs to compensate for different 
  146. aspects or to help interpret the fields w, h, x, y, pageWidth, and 
  147. pageHeight, which are in units of pixels. The fraction xAspect/yAspect 
  148. represents a pixel's width/height. It's recommended that your programs 
  149. store proper fractions in BitMapHeaders, but aspect ratios can always 
  150. be correctly compared with the the test
  151.  
  152. xAspect%yDesiredAspect = yAspect%xDesiredAspect
  153.  
  154. Typical values for aspect ratio are width : height = 10 : 11 (Amiga 
  155. 320 x 200 display) and 1 : 1 (Macintosh*).
  156.  
  157. The size in pixels of the source "page" (any raster device) is stored 
  158. in pageWidth and pageHeight, e.g. (320, 200) for a low resolution 
  159. Amiga display. This information might be used to scale an image or 
  160. to automatically set the display format to suit the image. (The image 
  161. can be larger than the page.)
  162.  
  163. CMAP
  164.  
  165. The optional (but encouraged) property "CMAP" stores color map data 
  166. as triplets of red, green, and blue intensity values. The n color 
  167. map entries ("color registers") are stored in the order 0 through 
  168. n-1, totaling 3n bytes. Thus n is the ckSize/3. Normally, n would 
  169. equal 2nPlanes.
  170.  
  171. A CMAP chunk contains a ColorMap array as defined below. (These typedefs 
  172. assume a C compiler that implements packed arrays of 3-byte elements.)
  173.  
  174. typedef struct {
  175.      UBYTE red, green, blue;  /* color intensities 0..255 */
  176.      } ColorRegister;    /* size = 3 bytes */
  177.  
  178. typedef ColorRegister ColorMap[n]; /* size = 3n bytes */
  179.  
  180. The color components red, green, and blue represent fractional intensity 
  181. values in the range 0 through 255 256ths. White is (255, 255, 255) 
  182. and black is (0, 0, 0). If your machine has less color resolution, 
  183. use the high order bits. Shift each field right on reading (or left 
  184. on writing) and assign it to (from) a field in a local packed format 
  185. like Color4, below. This achieves automatic conversion of images across 
  186. environments with different color resolutions. On reading an ILBM, 
  187. use defaults if the color map is absent or has fewer color registers 
  188. than you need. Ignore any extra color registers.
  189.  
  190. The example type Color4 represents the format of a color register 
  191. in working memory of an Amiga computer, which has 4 bit video DACs. 
  192. (The ":4" tells the C compiler to pack the field into 4 bits.)
  193.  
  194. typedef struct {
  195.      unsigned pad1 :4, red :4, green :4, blue :4;
  196.      } Color4; /* Amiga RAM format. Not filed. */
  197.  
  198. Remember that every chunk must be padded to an even length, so a color 
  199. map with an odd number of entries would be followed by a 0 byte, not 
  200. included in the ckSize.
  201.  
  202. GRAB
  203.  
  204. The optional property "GRAB" locates a "handle" or "hotspot" of the 
  205. image relative to its upper left corner, e.g. when used as a mouse 
  206. cursor or a "paint brush". A GRAB chunk contains a Point2D.
  207.  
  208. typedef struct {
  209.      WORD x, y;     /* relative coordinates (pixels) */
  210.      } Point2D;
  211.  
  212. DEST
  213.  
  214. The optional property "DEST" is a way to say how to scatter zero or 
  215. more source bitplanes into a deeper destination image. Some readers 
  216. may ignore DEST.
  217.  
  218. The contents of a DEST chunk is DestMerge structure:
  219.  
  220. typedef struct {
  221.      UBYTE depth;   /* # bitplanes in the original source   */
  222.      UBYTE pad1;    /* unused; for consistency put 0 here   */
  223.      UWORD planePick; /* how to scatter source bitplanes into destination */
  224.      UWORD planeOnOff;   /* default bitplane data for planePick  */
  225.      UWORD planeMask;    /* selects which bitplanes to store into */
  226.      } DestMerge;
  227.  
  228. The low order depth number of bits in planePick, planeOnOff, and planeMask 
  229. correspond one-to-one with destination bitplanes. Bit 0 with bitplane 
  230. 0, etc. (Any higher order bits should be ignored.) "1" bits in planePick 
  231. mean "put the next source bitplane into this bitplane", so the number 
  232. of "1" bits should equal nPlanes. "0" bits mean "put the corresponding 
  233. bit from planeOnOff into this bitplane". Bits in planeMask gate writing 
  234. to the destination bitplane: "1" bits mean "write to this bitplane" 
  235. while "0" bits mean "leave this bitplane alone". The normal case (with 
  236. no DEST property) is equivalent to planePick = planeMask = 2nPlanesJ- 
  237. 1.
  238.  
  239. Remember that color numbers are formed by pixels in the destination 
  240. bitmap (depth planes deep) not in the source bitmap (nPlanes planes 
  241. deep).
  242.  
  243. SPRT
  244.  
  245. The presence of an "SPRT" chunk indicates that this image is intended 
  246. as a sprite. It's up to the reader program to actually make it a sprite, 
  247. if even possible, and to use or overrule the sprite precedence data 
  248. inside the SPRT chunk:
  249.  
  250. typedef UWORD SpritePrecedence; /* relative precedence, 0 is the highest */
  251.  
  252. Precedence 0 is the highest, denoting a sprite that is foremost.
  253.  
  254. Creating a sprite may imply other setup. E.g. a 2 plane Amiga sprite 
  255. would have transparentColor = 0. Color registers 1, 2, and 3 in the 
  256. CMAP would be stored into the correct hardware color registers for 
  257. the hardware sprite number used, while CMAP color register 0 would 
  258. be ignored.
  259.  
  260. CAMG
  261.  
  262. A "CAMG" chunk is specifically for the Commodore Amiga computer. It 
  263. stores a LONG "viewport mode". This lets you specify Amiga display 
  264. modes like "dual playfield" and "hold and modify".
  265. 3. Standard Data Chunk
  266.  
  267. Raster Layout
  268.  
  269. Raster scan proceeds left-to-right (increasing X) across scan lines, 
  270. then top-to-bottom (increasing Y) down columns of scan lines. The 
  271. coordinate system is in units of pixels, where (0,0) is the upper 
  272. left corner.
  273.  
  274. The raster is typically organized as bitplanes in memory. The corresponding 
  275. bits from each plane, taken together, make up an index into the color 
  276. map which gives a color value for that pixel. The first bitplane, 
  277. plane 0, is the low order bit of these color indexes.
  278.  
  279. A scan line is made of one "row" from each bitplane. A row is one 
  280. planesU bits for one scan line, but padded out to a word (2 byte) 
  281. boundary (not necessarily the first word boundary). Within each row, 
  282. successive bytes are displayed in order and the most significant bit 
  283. of each byte is displayed first.
  284.  
  285. A "mask" is an optional "plane" of data the same size (w, h) as a 
  286. bitplane.  It tells how to "cut out" part of the image when painting 
  287. it onto another image."One" bits in the mask mean "copy the corresponding 
  288. pixel to the destination" while "zero" mask bits mean "leave this 
  289. destination pixel alone". In other words, "zero" bits designate transparent 
  290. pixels.
  291.  
  292. The rows of the different bitplanes and mask are interleaved in the 
  293. file (see below). This localizes all the information pertinent to 
  294. each scan line. It makes it much easier to transform the data while 
  295. reading it to adjust the image size or depth. It also makes it possible 
  296. to scroll a big image by swapping rows directly from the file without 
  297. random-accessing to all the bitplanes.
  298.  
  299. BODY
  300.  
  301. The source raster  is stored in a "BODY" chunk. This one chunk holds 
  302. all bitplanes and the optional mask, interleaved by row.
  303.  
  304. The BitMapHeader, in a BMHD property chunk, specifies the raster's 
  305. dimensions w, h, and nPlanes. It also holds the masking field which 
  306. indicates if there is a mask plane and the compression field which 
  307. indicates the compression algorithm used. This information is needed 
  308. to interpret the BODY chunk, so the BMHD chunk must appear first. 
  309. While reading an ILBM's BODY, a program may convert the image to another 
  310. size by filling (with transparentColor) or clipping.
  311.  
  312. The BODY's content is a concatenation of scan lines. Each scan line 
  313. is a concatenation of one row of data from each plane in order 0 through 
  314. nPlanes-1 followed by one row from the mask (if masking = hasMask 
  315. ). If the BitMapHeader field compression is cmpNone, all h rows are 
  316. exactly Ceiling(w/16) words wide. Otherwise, every row is compressed 
  317. according to the specified algorithm and their stored widths depend 
  318. on the data compression.
  319.  
  320. Reader programs that require fewer bitplanes than appear in a particular 
  321. ILBM file can combine planes or drop the high-order (later) planes. 
  322. Similarly, they may add bitplanes and/or discard the mask plane.
  323.  
  324. Do not compress across rows and don't forget to compress the mask 
  325. just like the bitplanes. Remember to pad any BODY chunk that contains 
  326. an odd number of bytes.
  327. 4. Nonstandard Data Chunk
  328.  
  329. The following data chunk was defined after various programs began 
  330. using FORM ILBM so it's a "nonstandard" chunk. That means there's 
  331. some slight chance of name collisions.
  332.  
  333. CRNG
  334.  
  335. A "CRNG" chunk contains "color register range" information. It's used 
  336. by Electronic Arts' Deluxe Paint program to identify a contiguous 
  337. range of color registers for a "shade range" and color cycling. There 
  338. can be zero or more CRNG chunks in an ILBM, but all should appear 
  339. before the BODY chunk. Deluxe Paint normally writes 4 CRNG chunks 
  340. in an ILBM when the user asks it to "Save Picture".
  341.  
  342. typedef struct {
  343.      WORD  pad1;    /* reserved for future use; store 0 here     */
  344.      WORD  rate;    /* color cycle rate */
  345.      WORD  active;  /* nonzero means cycle the colors  */
  346.      UBYTE low, high; /* lower and upper color registers selected     */
  347.      } CRange;
  348.  
  349. The fields low and high indicate the range of color registers (color 
  350. numbers) selected by this CRange.
  351.  
  352. The field active indicates whether color cycling is on or off. Zero 
  353. means off.
  354.  
  355. The field rate determines the speed at which the colors will step 
  356. when color cycling is on. The units are such that a rate of 60 steps 
  357. per second is represented as 214 = 16384. Slower rates can be obtained 
  358. by linear scaling: for 30 steps/second, rate = 8192; for 1 step/second, 
  359. rate = 16384/60 E 273.
  360.  
  361. CCRT
  362.  
  363. Commodore's Graphicraft program uses a similar chunk "CCRT" (for Color 
  364. Cyling Range and Timing). This chunk contains a CycleInfo structure.
  365.  
  366. typedef struct {
  367.      WORD  direction; /* 0 = don't cycle. 1 = cycle forwards (1, 2, 3).
  368.                  * -1 = cycle backwards (3, 2, 1) */
  369.      UBYTE start, end;  /* lower and upper color registers selected   */
  370.      LONG  seconds;    /* # seconds between changing colors */
  371.      LONG  microseconds; /* # microseconds between changing colors */ 
  372.      WORD  pad;          /* reserved for future use; store 0 here  */ 
  373.      } CycleInfo;
  374.  
  375. This is pretty similar to a CRNG chunk. A program would probably only 
  376. use one of these two methods of expressing color cycle data. You could 
  377. write out both if you want to communicate this information to both 
  378. Deluxe Paint and Graphicraft.
  379.  
  380. A CCRT chunk expresses the color cycling rate as a number of seconds 
  381. plus a number of microseconds.
  382.  
  383.  
  384. `0C
  385. Appendix A. ILBM Regular Expression
  386.  
  387. Here's a regular expression summary of the FORM ILBM syntax. This 
  388. could be an IFF file or a part of one.
  389.  
  390. ILBM ::= "FORM" #{  "ILBM" BMHD [CMAP] [GRAB] [DEST] [SPRT] [CAMG]
  391.      CRNG* CCRT* [BODY]  }
  392.  
  393. BMHD ::= "BMHD" #{  BitMapHeader   }
  394. CMAP ::= "CMAP" #{  (red green blue)*   } [0]
  395. GRAB ::= "GRAB" #{  Point2D   }
  396. DEST ::= "DEST" #{  DestMerge }
  397. SPRT ::= "SPRT" #{  SpritePrecendence   }
  398. CAMG ::= "CAMG" #{  LONG }
  399.  
  400. CRNG ::= "CRNG" #{  CRange    }
  401. CCRT ::= "CCRT" #{  CycleInfo }
  402. BODY ::= "BODY" #{  UBYTE*    } [0]
  403.  
  404. The token "#" represents a ckSize LONG count of the following {braced} 
  405. data bytes. E.g. a BMHD's "#" should equal sizeof(BitMapHeader). Literal 
  406. strings are shown in "quotes", [square bracket items] are optional, 
  407. and "*" means 0 or more repetitions. A sometimes-needed pad byte is 
  408. shown as "[0]".
  409.  
  410. The property chunks (BMHD, CMAP, GRAB, DEST, SPRT, and CAMG) and any 
  411. CRNG and CCRT data chunks may actually be in any order but all must 
  412. appear before the BODY chunk since ILBM readers usually stop as soon 
  413. as they read the BODY. If any of the 6 property chunks are missing, 
  414. default values are "inherited" from any shared properties (if the 
  415. ILBM appears inside an IFF LIST with PROPs) or from the reader program's 
  416. defaults. If any property appears more than once, the last occurrence 
  417. before the BODY is the one that counts since that's the one that modifies 
  418. the BODY.
  419.  
  420.  
  421. `0C
  422. Appendix B. ILBM Box Diagram
  423.  
  424. Here's a box diagram for a simple example: an uncompressed image 320 
  425. x 200 pixels x 3 bitplanes. The text to the right of the diagram shows 
  426. the outline that would be printed by the IFFCheck utility program 
  427. for this particular file.
  428.  
  429.  
  430.         +-----------------------------------+
  431.         |'FORM'         24070               |   FORM 24070 IBLM
  432.         +-----------------------------------+
  433.         |'ILBM'                             |
  434.         +-----------------------------------+
  435.         | +-------------------------------+ |
  436.         | | 'BMHD'      20                | |   .BMHD  20
  437.         | | 320, 200, 0, 0, 3, 0, 0, ...  | |
  438.         | + ------------------------------+ |
  439.         | | 'CMAP'      21                | |   .CMAP  21
  440.         | | 0, 0, 0; 32, 0, 0; 64,0,0; .. | |
  441.         | +-------------------------------+ |
  442.         | 0                                 |
  443.         +-----------------------------------+
  444.         |'BODY'         24000               |   .BODY 24000
  445.         |0, 0, 0, ...                       |
  446.         +-----------------------------------+
  447.  
  448.  
  449.  
  450. The "0" after the CMAP chunk is a pad byte.
  451.  
  452.  
  453. `0C
  454. Appendix C. ByteRun1 Run Encoding
  455.  
  456. The run encoding scheme byteRun1 is best described by psuedo code 
  457. for the decoder Unpacker (called UnPackBits in the Macintosh* toolbox):
  458.  
  459. UnPacker:
  460.      LOOP until produced the desired number of bytes
  461.           Read the next source byte into n
  462.           SELECT n FROM
  463.                [0..127]  => copy the next n+1 bytes literally
  464.                [-1..-127]     => replicate the next byte -n+1 times
  465.                -128 => noop
  466.                ENDCASE;
  467.           ENDLOOP;
  468.  
  469. In the inverse routine Packer, it's best to encode a 2 byte repeat 
  470. run as a replicate run except when preceded and followed by a literal 
  471. run, in which case it's best to merge the three into one literal run. 
  472. Always encode 3 byte repeats as replicate runs.
  473.  
  474. Remember that each row of each scan line of a raster is separately 
  475. packed.
  476.  
  477.  
  478. `0C
  479. Appendix D. Standards Committee
  480.  
  481. The following people contributed to the design of this FORM ILBM standard:
  482.  
  483. Bob "Kodiak" Burns, Commodore-Amiga
  484. R. J. Mical, Commodore-Amiga
  485. Jerry Morrison, Electronic Arts
  486. Greg Riker, Electronic Arts
  487. Steve Shaw, Electronic Arts
  488. Dan Silva, Electronic Arts
  489. Barry Walsh, Commodore-Amiga
  490.  
  491.